<?php

class EditionTexte extends CI_Controller
{
	public function __construct()
	{
		parent::__construct();
		
		$this->load->model('ActionsDeCommunication/ActionDeCommunication');
		$this->load->model('Utilisateurs/Enseignant');
		$this->load->model('Utilisateurs/Etudiants');
	}
	
	public function accueil()
	{
		$data['onglet_ouvert'] = '';
		
		if(isset($_POST['enregistrer']))
		{
			if (get_magic_quotes_gpc())
				$value = htmlspecialchars(stripslashes((string)$_POST['editor']));
			else
				$value = htmlspecialchars((string)$_POST['editor']);
		
			$handle = fopen(textes_chemin('pageAccueil','html'), "w");
			fputs($handle, $value);
			fclose($handle);
			redirect(base_url().'index.php/Administration/parametre');
		}
		
		$this->load->view('Global/entete.php', $data);
		$this->load->view('EditionTexte/v_editerPageAccueil.php', $data);
		$this->load->view('Global/piedpage.php');
	}
	
	public function mails()
	{
		$this->load->model('MailManager');
		
		$data['onglet_ouvert'] = '';
		
		if(isset($_POST['mail']) && $_POST['mail'] != 'aucun' && !isset($_POST['enregistrer']))
		{
			$mail = new MailManager();
			$mail->setFileName($_POST['mail']);
			$mail->load();
		}
		elseif(isset($_POST['enregistrer']))
		{
			$mail = new MailManager();
			$mail->setObjet($_POST['objet']);
			$mail->setContenu($_POST['editor']);
			$mail->setFileName($_POST['mail']);
 			if(!$mail->save())
 				$data['flash_erreur'] = $this->session->flashdata('La sauvegarde du mail a échouée');
 			else
 				$data['flash_erreur'] = $this->session->flashdata('La sauvegarde du mail a réussie');
 			redirect(base_url().'index.php/Administration/parametre');
		}
		else
		{
			$mail = new MailManager();
			$mail->setContenu('Choississez un mail à éditer');
		}

		$data['mail'] = $mail;
		
		$this->load->view('Global/entete.php', $data);
		$this->load->view('EditionTexte/v_editerMails.php', $data);
		$this->load->view('Global/piedpage.php');
	}
}
?>